import java.util.LinkedList;
import java.util.Queue;
import java.util.Scanner;

public class Main {
    private Queue<Integer> patientQueue = new LinkedList<>();
    private boolean acceptingNewPatients = true;

    public static void main(String[] args) {
        Main system = new Main();
        system.run();
    }

    public void run() {
        Scanner scanner = new Scanner(System.in);
        int choice;

        do {
            printMenu();
            choice = scanner.nextInt();

            switch (choice) {
                case 1:
                    if (acceptingNewPatients) {
                        System.out.print(">>输入病历号:");
                        int recordNumber = scanner.nextInt();
                        patientQueue.add(recordNumber);
                    } else {
                        System.out.println(">>当前不再接受新病人排队");
                    }
                    break;
                case 2:
                    if (!patientQueue.isEmpty()) {
                        System.out.println(">>病人" + patientQueue.poll() + "就诊");
                    } else {
                        System.out.println(">>没有病人在排队");
                    }
                    break;
                case 3:
                    displayQueue();
                    break;
                case 4:
                    acceptingNewPatients = false;
                    displayRemainingPatients();
                    break;
                case 5:
                    System.out.println(">>下班");
                    break;
                default:
                    System.out.println(">>无效选择");
            }
        } while (choice != 5);

        scanner.close();
    }

    private void printMenu() {
        System.out.println("1:排队 2:就诊 3:查看排队 4.不再排队,余下依次就诊 5:下班 请选择:");
    }

    private void displayQueue() {
        if (patientQueue.isEmpty()) {
            System.out.println(">>没有病人在排队");
        } else {
            System.out.print(">>排队病人:");
            for (Integer record : patientQueue) {
                System.out.print(record + " ");
            }
            System.out.println();
        }
    }

    private void displayRemainingPatients() {
        if (patientQueue.isEmpty()) {
            System.out.println(">>没有病人需要就诊");
        } else {
            System.out.print(">>病人按以下顺序就诊:");
            while (!patientQueue.isEmpty()) {
                System.out.print(patientQueue.poll() + " ");
            }
            System.out.println();
        }
    }
}